<%@ page import="java.net.URLDecoder" %>
<%@ page import="net.ifilm.common.Constants" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    int currentNums = 0;
    final int maxNums = 5;  // 最多显示5条播放记录
    String cookieName;
    String cookieValue;
%>
<script type="text/javascript">
    $(document).ready(function() {
//        $(".signin").click(function(e) {
//            var top = e.pageY;
//            var left = e.pageX;
//            $("fieldset#signin_menu").css({"top":top,"left":left});
//            $("fieldset#signin_menu").toggle();
//        });
//
//        $('#signin_menu input[name="imageCode"]').focus(refreshCode);
//        $('#signin_menu p a').click(refreshCode);
//
//        function refreshCode(){
//        $('#signin_menu p a img').attr("src", "/verifyCode?"+Math.random());
//    }

        $('#search-form a').click(submitSearchForm);
        var searchInput = $('#search-form input[name="searchKey"]'); // 搜索输入框
        searchInput.bind("input keydown focus blur", function(event) {
            if (event.type == 'input') {
                if (searchInput.val() == null || searchInput.val() == "") return;
                searchInput.AutoComplete({
                    'data': "/autoFilmName.html?timestamp=" + new Date().getTime(),
                    'ajaxParams':{'searchKey': searchInput.val()},
                    'ajaxDataType': 'xml',
                    'width': 270,
                    'maxItems': 20,
                    'ajaxType':'POST',
                    'emphasis': false,
                    'maxHeight': 400,
                    'async': true,
                    'onerror': function(msg){  }
                });
            } else if (event.type == 'keydown') {
                if (e.keyCode == 13) submitSearchForm();
            } else if (event.type == 'focus') {
                if (searchInput.val() == "请输入电影关键字") {
                    searchInput.css("color", "black");
                    searchInput.val("");
                }
            } else if (event.type == 'blur') {
                if(searchInput.val() == "") {
                    searchInput.css("color", "#C2C2C2");
                    searchInput.val("请输入电影关键字");
                }
            }
        });


        $('.chromestyle ul li:last-child').mousedown(function(e) {
            var left = $('.chromestyle ul li:last-child').position().left - 172;
            $(".historyTip").css({"top":23,"left":left});
            $(".historyTip").css("display", "block");
        });
        $('.pl_his_bot a:contains("关闭")').click(function() {
            $(".historyTip").css("display", "none");
        });
        $('.pl_his_bot a:contains("清空记录")').click(function() {
            var strCookie=document.cookie;
            var arrCookie=strCookie.split("; ");

            for(var i=0;i <arrCookie.length;i++) {
                var arr = arrCookie[i].split("=");
                if(arr.length > 0 && arr[0].indexOf("5ifilm.film") != -1) {
                    DelCookie(arr[0]);
                }
            }

            $("#history-panel").empty();
            $('<li style="padding-top:12px;padding-bottom:6px;text-align:center;color:#666">暂时还没有您的观看记录</li>')
                    .appendTo($("#history-panel"));
        });

    });

    function submitSearchForm() {
        var searchValue = document.searchForm.searchKey.value;
        if (searchValue == '' || searchValue == '请输入电影关键字') return;
//        document.searchForm.method = 'POST';
//        document.searchForm.page.value = '1';
        // 参数queryType=1表示是搜索查询
        document.searchForm.submit();
    }

    function GetCooki(offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
            endstr = document.cookie.length;
        return decodeURIComponent(document.cookie.substring(offset, endstr));
    }

    function DelCookie(name) {
        var exp = new Date();
        exp.setTime (exp.getTime() - 1);
        var cval = GetCookie (name);
        document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
    }

    function GetCookie(name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
                return GetCooki (j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }

    function menuNewUpdate(page, sortColumn) {
        var form = createForm('/page/filmListByCondition.html');
        createInput("page", page, form);
        createInput("sortColumn", sortColumn, form);
        submitForm(form);
    }

    function menuEthics(page, filmTypeId) {
        var form = createForm('/page/filmListByCondition.html');
        createInput("page", page, form);
        createInput("filmTypeId", filmTypeId, form);
        submitForm(form);
    }

    function menuTelevision(page, orderTime, regionId, type) {
        var form = createForm('/page/filmListByCondition.html');
        createInput("page", page, form);
        createInput("orderTime", orderTime, form);
        createInput("regionId", regionId, form);
        createInput("type", type, form);
        submitForm(form);
    }

    function menuCartoonFunny(page, orderTime, type) {
        var form = createForm('/page/filmListByCondition.html');
        createInput("page", page, form);
        createInput("orderTime", orderTime, form);
        createInput("type", type, form);
        submitForm(form);
    }
</script>

<div class="top">
	<div class="Logo">
		<a href="http://www.5ifilm.net"><img class="img" src="/upload/logo/logo.png" /></a>
        <span><img class="img" src="/images/ugc_logo.png" /></span>
	</div>
	<div class="logo_right">
		<div class="top_top">
			<div class="top_banner_l"></div>
			<div class="chromestyle" id="langen">
				<ul>
					<li><a href="javascript:setHomePage(window.location);">把5ifilm设为主页</a></li>
					<li><a href="javascript:addFavorites(window.location,document.title);">加入收藏</a></li>
					<li><a href="javascript:void(0);" onclick="javascript:dynamicListMessageSubmit('1');">留言求片</a></li>
					<li><a href="javascript:alert('未实现');">放到桌面</a></li>
					<li><a href="javascript:alert('未实现');">网站地图</a></li>
                    <li><a href="javascript:void(0);"><img src="/images/butt_arrow_down.gif" />观看历史</a></li>
				</ul> 
				<span><%--<a href="javascript:void(0);">注册一个帐号？</a>--%><%--<a href="javascript:void(0);" class="signin">登陆</a>--%></span>
			</div>
			<div class="top_banner_r"></div>
		</div>

	</div>
    <div class="nofloat"></div>
</div>

<div class="menu">
	<div class="menu_m">
        <form id="search-form" name="searchForm" action="filmListByCondition.html?queryType=1" method="POST">
            <input type="text" name="searchKey" value="请输入电影关键字" />
            <input type="hidden" name="page" value='1'>
            <a class="search-form-submit"></a>
        </form>
        <ul class="menu_ul">
            <li><a href="javascript:void(0);" onclick="javascript:location.href='/index.html';"><span>首页</span></a></li>
            <li><a href="javascript:void(0);" onclick="javascript:menuNewUpdate('1', 'createtime');"><span>最新更新</span></a></li>
            <li><a href="javascript:void(0);" onclick="javascript:menuTelevision('1', 'playnum', '3', '2');"><span>内地剧场</span></a></li>
            <li><a href="javascript:void(0);" onclick="javascript:menuTelevision('1', 'playnum', '2', '2');"><span>港台剧场</span></a></li>
            <li><a href="javascript:void(0);" onclick="javascript:menuTelevision('1', 'playnum', '4', '2');"><span>欧美剧场</span></a></li>
            <li><a href="javascript:void(0);" onclick="javascript:menuTelevision('1', 'playnum', '1', '2');"><span>日韩剧场</span></a></li>
            <li><a href="javascript:void(0);" onclick="javascript:menuCartoonFunny('1', 'playnum', '4');"><span>动漫大全</span></a></li>
            <li><a href="javascript:void(0);" onclick="javascript:menuCartoonFunny('1', 'playnum', '3');"><span>综艺娱乐</span></a></li>
            <% if (Constants.switchSex) { %>
            <li><a href="javascript:void(0);" onclick="javascript:menuEthics('1', '100');"><span>伦理片</span></a></li>
            <% } else { %>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <% } %>
            <!--
            <li><a href="/page/pic/picture.jsp"><span>热图</span></a></li>
            -->
            <li><a href="javascript:void(0);" onclick="javascript: alert('等待开放，敬请关注，谢谢！');"><span>热图</span></a></li>
        </ul>
    </div>
</div>


<%--<!-- 登陆框组件栏目 -->--%>
<%--<fieldset id="signin_menu">--%>
    <%--<form action="#" id="signin" method="post">--%>
        <%--<label for="username">登陆名/电子邮件</label>--%>
        <%--<input type="text" name="username" id="username">--%>
        <%--<p></p>--%>
        <%--<p>--%>
            <%--<label for="password">密码</label>--%>
            <%--<input type="password" name="password" id="password">--%>
        <%--</p>--%>
        <%--<p>--%>
            <%--<label for="password">验证码</label>--%>
            <%--<input type="text" name="imageCode">--%>
            <%--<a href="javascript:void(0);"><img src="/images/code.jpg" width="76" height="21" /></a>--%>
        <%--</p>--%>
        <%--<p class="remember">--%>
            <%--<input type="submit" value="登陆" id="signin_submit">--%>
            <%--<input type="button" value="关闭" class="signin_submit" onclick="$('#signin_menu').css('display', 'none')">--%>
            <%--<input type="checkbox" value="1" name="remember_me" id="remember">--%>
            <%--<label for="remember">记住</label>--%>
        <%--</p>--%>
    <%--</form>--%>
<%--</fieldset>--%>


<div class="historyTip">
    <ul id="history-panel">
        <%
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                boolean flag = true;
                int i;
                for (i = 0; i < cookies.length; i++) {
                    cookieName = cookies[i].getName();
                    cookieValue = URLDecoder.decode(cookies[i].getValue(), "utf-8");
                    if (!cookieName.contains("5ifilm.film")) continue;

                    if (i >= maxNums) {
                        currentNums += maxNums;
        %>
                    <li id='moreli' style="text-align:center;color:#666;" onclick="javascript:showMoreHistory();">....................</li>
        <%
                        break;
                    }

                    String[] splitStr = cookieValue.split(",");
                    flag = false;
        %>
                    <li>
                        <i></i>
                        <a title="<%=splitStr[1]%>" href="javascript:void(0);" onclick="javascript:location.href='/page/playFilm.html?filmId=<%=splitStr[0]%>';">
                            <h4><%=splitStr[1]%></h4>
                        </a>
                        <a class="r" href="javascript:void(0);" onclick="javascript:location.href='/page/playFilm.html?filmId=<%=splitStr[0]%>';">[观看]</a>
                    </li>
        <%
                }

                if (flag) {
        %>
                    <li style="padding-top:12px;padding-bottom:6px;text-align:center;color:#666">暂时还没有您的观看记录</li>
        <%
                }
            }
        %>
        <div class="clear-all"></div>
    </ul>
    <div class="pl_his_bot">
        <a href="javascript:void(0)">关闭</a> <span>&nbsp;</span>
        <a href="javascript:void(0)">清空记录</a>
        <a href="javascript:void(0)" title="更多观看历史" class="r">查看更多历史</a>
    </div>
</div>

<script type="text/javascript">
    function showMoreHistory() {
        var playHistoryUl = document.getElementById('history-panel');
        var moreli = document.getElementById("moreli");
        if (moreli == null || moreli == 'undified') return;
        playHistoryUl.removeChild(moreli);

        <%
            cookies = request.getCookies();
            if (cookies != null) {
                for (int i = currentNums; i < cookies.length; i++) {
                    cookieName = cookies[i].getName();
                    cookieValue = URLDecoder.decode(cookies[i].getValue(), "utf-8");
                    if (!cookieName.contains("5ifilm.film")) continue;

                    String[] splitStr = cookieValue.split(",");
        %>
                    var rootLi = document.createElement("li");
                    var li = document.createElement("i");
                    rootLi.appendChild(li)

                    var linka = document.createElement("a");
                    linka.title = '<%=splitStr[1]%>';
                    linka.href = 'javascript:void(0);';
                    var h4 = document.createElement("h4");
                    h4.innerText = '<%=splitStr[1]%>';
                    linka.appendChild(h4);
                    rootLi.appendChild(linka);

                    var a = document.createElement("a");
                    a.className = 'r';
                    a.href = 'javascript:void(0);';
                    a.innerText = '[观看]';
                    rootLi.appendChild(a);

                    playHistoryUl.appendChild(rootLi);
        <%
                }
            }
        %>
    }

    $('.pl_his_bot a:contains("查看更多历史")').click(function() {
        showMoreHistory();
    });
</script>